using UnityEngine;
using System.Collections;

public class PowerUpsManager : DrawableGameObject 
{
	public float currentCoolDown;
	public float coolDown;
	
	public static bool isPrepared = true;
	public Texture2D[] able;
	public Texture2D[] disable;
	PlayerMechanic playerMechanic;
	public PlayerState playerState;
	GameObject player;
    private bool itsMe = false;
	
	public override void Start () 
	{
		base.Start();

        isPrepared = true;
		currentCoolDown = coolDown;
		SetAnimations(able, disable, null, null, null);
		player = GameObject.FindGameObjectWithTag("Player");
		playerMechanic = player.GetComponent<PlayerMechanic>();
	}
	
	void Update ()
	{
		if(!isPrepared){
			
			this.currentCoolDown += Time.deltaTime;
			
			if(this.currentCoolDown > coolDown && itsMe)
			{
			    isPrepared = true;
                itsMe = false;
			}
			
			RunAnimation("Second", "Loop");	
			
		}else{
			RunAnimation("First", "Loop");
			
		}
		
	}
	
	void OnMouseDown()
	{
		if(isPrepared && this.playerMechanic.getPlayerState() == PlayerState.Normal)
		{
			this.playerMechanic.ChangeMode(this.playerState);
            itsMe = true;
			isPrepared = false;
			this.currentCoolDown = 0;
		}
	}
	
	public void Use()
	{
		this.playerMechanic.ChangeMode(this.playerState);
		isPrepared = false;
		this.currentCoolDown = 0;
        itsMe = true;
	}
}
